package rosedb.model;


import java.io.File;

import java.io.Serializable;
import java.util.TreeMap;
import rosedb.control.Controller;

/**
 *
 * @author riu
 */
public class Rose implements Serializable{
    private TreeMap<String, String> data = null;
    private int images = 0;

    public Rose(String name) {
        data = new TreeMap<String, String>();
        data.put("name", name);
        
    }

    public synchronized int getImageCount() {
        int count=0;
        File f = new File(Controller.DATA_DIR+"roses/"+getName().toLowerCase()+"/img"+count+".jpg");
        
        while(f.exists()){
            count++;
            f = new File(Controller.DATA_DIR+"roses/"+getName().toLowerCase()+"/img"+count+".jpg");
        }
        return count;
    }

    public TreeMap<String, String> getData() {
        return data;
    }


    public String getName(){
        return data.get("name");
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Rose && ((Rose)obj).getName().equalsIgnoreCase(this.getName().toLowerCase()))
            return true;

        return false;
    }

    @Override
    public int hashCode() {
        return getName().hashCode();
    }





    



}
